home *** CD-ROM | disk | FTP | other *** search
- ; csetup.a - initialize C program.
- ; (C) Copyright 1984, 1985 Gregory R. Mansfield - All Rights Reserved
- ; G. R. Mansfield. 84/06/01.
- ; Ver 2.0-5517.
-
-
- include "include/msdos.ah"
- include "include/ascii.ah"
-
- ; MS-DOS offsets relative to DS.
-
- CML equ 00081h ; command line
- EAB equ 00002h ; end of allocated block
-
- ; Linker data offsets relative to SS.
-
- UDA equ 00000h ; unitialized data address
- UDL equ 00002h ; unitialized data length
-
- ; csetup values.
-
- APTL equ 512*2 ; length of apt
-
-
- dseg
- public errno_
- public _mcv
- public _pfb
-
- errno_ dw 0
- _mcv dw 0,0 ; memory control vector
- _pfb dw 0 ; program prefix block
-
- mmea db 'not enough memory',CV_LF,'$'
-
- cseg
- public _csetup
- public exit_
- public main_
- public _setargs_
-
-
- ; mme - memory error.
-
- mme: mov dx,offset mmea ; display memory error
- mov ax,ss
- mov ds,ax
- mov ah,FR_DST
- int I_FCN
- jmp exit_
-
-
- ; _csetup - initialize C program execution.
-
- _csetup:
- cld
- mov ax,ds ; save program prefix block segment
- mov ss:_pfb,ax
- mov ax,[EAB] ; check data segment length
- mov bx,ss
- sub ax,bx
- jbe mme ; if room for data segment
- dec ax ; ds = max(space, 64K)
- mov bx,00FFFh
- cmp ax,bx
- jb csu1
- mov ax,bx
- csu1: mov cl,4 ; maximum offset
- shl ax,cl
- mov bx,7Fh ; check stack setting
- mov di,ss:[UDA] ; start of uninitialized data
- add bx,di
- add bx,ss:[UDL] ; length of uninitialized data
- cmp sp,bx
- jnz csu4 ; if stack set by linker
- mov sp,ax ; stack at maximum offset
- csu4: cmp bx,ax
- jae mme ; if no room
-
- ; copy argument string.
-
- push ss
- pop es
- mov bx,di
- mov si,CML-1 ; copy argument string
- lodsb
- cbw
- mov cx,ax
- rep movsb
- xchg al,ch
- stosb
- push es
- pop ds
- push di ; save start of apt
- mov bp,sp
- push bx ; s
- push di ; apt
- add di,APTL ; ast
- push di
- call _setargs_ ; setargs(ast, apt, s);
- cld
- mov sp,bp
- pop bx ; apt
- mov si,[bx] ; ast
- add bx,ax
- add bx,ax
- mov cx,[bx] ; end of ast = apt[aptl]
- sub cx,si ; astl
- sub sp,cx ; copy ast to stack
- and sp,0FFFEh
- mov di,sp
- rep movsb
- mov cx,ax ; argv = apt with adjustment
- sub di,si
- arg1: dec bx
- dec bx
- mov dx,[bx]
- add dx,di
- push dx
- loop arg1
- mov dx,sp ; *argv
- push dx
- push ax ; argc
-
- mov di,[UDA] ; start of uninitialized data
- mov cx,[UDL] ; length of uninitialized data
- xor ax,ax
- rep stosb
- add di,2 ; set low memory address
- and di,-2
- mov _mcv,di
- mov _mcv+2,di
- call main_ ; main(argc, argv)
- mov al,0 ; exit code = 0
- push ax
- push ax
-
- ; exit(code)
- ; int code;
-
- exit_: pop ax ; skip return address
- pop ax ; return code
- ext1: mov ah,FR_TRP
- int I_FCN
-